﻿namespace ExamV5.StudyInfo
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmShowLessionInfo : Page
    {
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        protected Label labLessionTitle;
        protected Label labTip;
        private PublicFun publicFun_0 = new PublicFun();
        protected int strLessionID = 0;
        protected string strURL = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---查看电子课件";
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamDeptID");
            this.httpCookie_1 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 == null) || (this.httpCookie_0.Value == ""))
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
            else
            {
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.strLessionID = Convert.ToInt32(base.Request["ID"]);
                if (!base.IsPostBack)
                {
                    this.labTip.Text = string.Concat(new object[] { "<a href='#' onclick=javascript:myStudyLog('", this.strLessionID, "');><img src='../image/menuico/Menu17.gif' border=0></img> <font color=blue>我的笔记</font></a>  &nbsp;&nbsp;<a href='#' onclick=javascript:heStudyLog('", this.strLessionID, "');><img src='../image/menuico/MenuTE.gif' border=0></img> <font color='#ff6600'>他人笔记</font></a>  &nbsp;&nbsp;<a href='FrmForumStudy.aspx?Flag=L&ID=", this.strLessionID, "' target=_blank><img src='../image/menuico/Menu287.gif' border=0></img> <font color=green>讨论交流</font></a>" });
                    string str7 = "0";
                    string str8 = "0";
                    string s = "";
                    this.publicFun_0.ExecuteSql("update LessionInfo set ReadNum=ReadNum+1 where ID=" + this.strLessionID);
                    string cmdText = string.Concat(new object[] { "select a.LessionLoadFile,a.LessionName,a.FenValue,a.RemoveFen from LessionInfo a,TypeList b where b.ID=a.LessionTypeID and (b.BrowUserCode like '%,", this.httpCookie_0.Value, ",%' or b.BrowUserCode like '%,所有人员,%' or b.BrowDeptID like '%,", this.httpCookie_1.Value, ",%' or b.BrowDeptName like '%,所有部门,%'  )  and a.ID=", this.strLessionID });
                    SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                    connection.Open();
                    SqlCommand command = new SqlCommand(cmdText, connection);
                    SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                    if (reader.Read())
                    {
                        str7 = reader["FenValue"].ToString();
                        str8 = reader["RemoveFen"].ToString();
                        s = reader["LessionLoadFile"].ToString();
                        this.labLessionTitle.Text = reader["LessionName"].ToString();
                    }
                    reader.Close();
                    command.Dispose();
                    connection.Close();
                    connection.Dispose();
                    if (str7.Trim() == "")
                    {
                        str7 = "0";
                    }
                    if (str8.Trim() == "")
                    {
                        str8 = "0";
                    }
                    if (!(this.publicFun_0.GetValues("select a.UserCode  from UserInfo a,MemberLevel b where getdate()>DateAdd(dd,b.RemoveValue,Convert(dateTime,a.UpdateTime)) and a.UserMember=b.ID and a.UserCode='" + this.httpCookie_0.Value + "' and LevelRemove='C'", "UserCode") == ""))
                    {
                        s = "";
                        this.publicFun_0.ExecuteSql("update UserInfo set UserFen=0 where UserCode='" + this.httpCookie_0.Value + "'");
                        base.Response.Write("<script>alert('会员积分不足,充值方可进行查看电子课件！');window.close();</script>");
                    }
                    else
                    {
                        if (this.publicFun_0.GetValues(string.Concat(new object[] { "select ID from UserStudyFen where UserCode='", this.httpCookie_0.Value, "' and ExamorStudy='K' and Formtable='LessionInfo' and FormID=", this.strLessionID }), "ID").Trim() == "")
                        {
                            if (!this.publicFun_0.OpertionMemberFen(this.httpCookie_0.Value, Convert.ToInt32(str8)))
                            {
                                s = "";
                                base.Response.Write("<script>alert('会员积分不足,充值方可进行查看电子课件！');window.close();</script>");
                                return;
                            }
                            double num2 = 0.0;
                            num2 = Convert.ToDouble(str7);
                            this.publicFun_0.ExecuteSql(string.Concat(new object[] { "delete  UserStudyFen where ExamOrStudy='K' and UserCode='", this.httpCookie_0.Value, "' and Formtable='LessionInfo' and FormID=", this.strLessionID, ";insert into UserStudyFen(UserCode,ExamStudyName,StudyFen,Formtable,FormID,ExamOrStudy) values('", this.httpCookie_0.Value, "','", this.labLessionTitle.Text, "','", num2, "','LessionInfo','", this.strLessionID, "','K')" }));
                        }
                        if (s.ToLower().IndexOf("http://") == -1)
                        {
                            if (s.IndexOf(".") != -1)
                            {
                                string str3 = FormsAuthentication.HashPasswordForStoringInConfigFile(this.httpCookie_0.Value, "MD5").Trim();
                                if (str3.Length > 20)
                                {
                                    str3 = str3.Substring(0, 20);
                                }
                                string str4 = base.Server.HtmlEncode(s);
                                string str6 = s.Substring(s.LastIndexOf(".") + 1).ToLower();
                                str4 = str4.Substring(0, (str4.Length - str6.Length) - 1);
                                string str = ((str6.Length.ToString() + str3.Substring(0, 7)) + str6.Substring(0, 1) + str3.Substring(7, 8)) + str6.Substring(1, 1) + str4.Substring(0, 3);
                                if (str6.Length > 2)
                                {
                                    str = str + str6.Substring(2);
                                }
                                str = (str + str3.Substring(15) + str4.Substring(3)).ToLower();
                                switch (s.Substring(s.LastIndexOf(".")).ToLower())
                                {
                                    case ".rmvb":
                                        this.strURL = "FrmShowRA.aspx?strName=" + str;
                                        return;

                                    case ".ra":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".mid":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".wmv":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".wma":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".avi":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".mpeg":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".mpg":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".asf":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".asx":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".mp3":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".mp4":
                                        this.strURL = "FrmShowMD.aspx?strName=" + str;
                                        return;

                                    case ".rm":
                                        this.strURL = "FrmShowRA.aspx?strName=" + str;
                                        return;

                                    case ".flv":
                                        this.strURL = "FrmShowLV.aspx?strName=" + str;
                                        return;

                                    case ".htm":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".mht":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".html":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".doc":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".docx":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".pdf":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".swf":
                                        this.strURL = "FrmShowSW.aspx?strName=" + str;
                                        return;

                                    case ".pps":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".ppt":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;

                                    case ".pptx":
                                        this.strURL = "FrmShowIE.aspx?strName=" + str;
                                        return;
                                }
                                this.strURL = "FrmShowIE.aspx?strName=" + str;
                            }
                            else
                            {
                                this.strURL = "#";
                                base.Response.Write("<script>alert('课件文件非法,无法浏览,可能是浏览权限未开放！')</script>");
                            }
                        }
                        else
                        {
                            this.strURL = s;
                        }
                    }
                }
            }
        }
    }
}

